package cn.sc.allinpay.allfavour.business.splash;

import android.animation.Animator;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.AppCompatImageView;
import android.view.View;
import android.view.ViewPropertyAnimator;

import butterknife.BindView;
import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.base.activity.BaseActivity;


/**
 * activity 启动
 * author：pany
 * on 2017/12/1 11:14
 */
public class SplashActivity extends BaseActivity<SplashContract.View, SplashContract.Presenter>
        implements SplashContract.View {

    @BindView(R.id.ivLogo)
    AppCompatImageView ivLogo;

    @Override
    protected void layoutPre(Bundle savedInstanceState) {
        super.layoutPre(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0及以上
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            getWindow().setStatusBarColor(getResources().getColor(R.color.bg_color));
        }
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_splash;
    }

    @Override
    protected SplashContract.Presenter bindPresenter() {
        return new SplashPresenter();
    }

    @Override
    protected void layoutContent(Bundle savedInstanceState) {
        ViewPropertyAnimator animator = ivLogo.animate();
        animator.scaleY(1.5f);
        animator.scaleX(1.2f);
        animator.setDuration(2000);
        animator.setListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (presenter != null) {
                    presenter.setAnimateFinish();
                    presenter.startActivity();
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animator.start();
    }
}
